/**
 * @author 雷明浩
 * @date 2025/6/3 11:43
 */
public class Merge {
    //newcoder 合并两个有序链表
    // https://www.nowcoder.com/practice/d8b6b4358f774294a89de2a6ac4d9337?tpId=295&tags=&title=&difficulty=0&judgeStatus=0&rp=0&sourceUrl=%2Fexam%2Foj%3FquestionJobId%3D10%26subTabName%3Donline_coding_page
    public ListNode Merge (ListNode pHead1, ListNode pHead2) {
        // write code here
        ListNode cur1 = pHead1;
        ListNode cur2 = pHead2;
        ListNode pHead = new ListNode(-1);
        ListNode cur = pHead;
        while (cur1 != null && cur2 != null) {
            if (cur1.val < cur2.val) {
                cur.next = cur1;
                cur1 = cur1.next;
            }else {
                cur.next = cur2;
                cur2 = cur2.next;
            }
            cur = cur.next;
        }
        if (cur1 != null) {
            cur.next = cur1;
        }
        if (cur2 != null) {
            cur.next = cur2;
        }
        return pHead.next;
    }
}